package com.memoir.exception;

import com.memoir.common.response.ServerResponse;
import com.memoir.model.enums.ResponseConstantEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public ServerResponse businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return ServerResponse.buildError(e.getCode(), e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public ServerResponse runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        return ServerResponse.buildError(ResponseConstantEnums.ERROR);
    }
}
